package com.sanshengshui.netty.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.net.InetSocketAddress;

public class EchoServer {

    public static void main(String[] args) throws InterruptedException {
           new EchoServer().start();
    }

    public  void start() throws InterruptedException {
        EventLoopGroup group = new NioEventLoopGroup();
       try {
           ServerBootstrap b = new ServerBootstrap();
           b.group(group).channel(NioServerSocketChannel.class).
           localAddress(new InetSocketAddress(8888)).childHandler(new EchoServerInitializer());
           ChannelFuture f =b.bind().sync();
           f.channel().closeFuture().sync();
       }finally {
           group.shutdownGracefully().sync();
       }
    }
}
